package com.scfw.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by sehuaqi on 2017/7/3.
 */
@RestController
@RequestMapping(value = "/mongo")
public class CustomerController {

    @Autowired
    private  CustomerRepository repository;

    @RequestMapping(value = "/initData")
    public String initData(){

        //repository.deleteAll();
        repository.save(new Customer("qisehua","7sh"));
        repository.save(new Customer("七色花","qisehua"));

        return "succ";
    }

    @RequestMapping(value = "/findAll")
    public List<Customer> findAll(){

        List<Customer> customers = repository.findAll();

        return customers;
    }

    @RequestMapping(value = "/findByLastName/{name}")
    public List<Customer> findByLastName(@PathVariable String name){

        List<Customer> customers = repository.findByLastName(name);

        return customers;
    }

}
